11 const int MAXN
= 1000, MAXC
= 100;
16 edge(int I
, int G
, int W
) : i(I
), g(G
), w(W
) {}
17 bool operator < (const edge
&that
) const {
22 int p
[MAXN
], d
[MAXN
][MAXC
+1], n
;
26 int dijkstra(const int &start
, const int &end
, const int &c
){
27 for (int i
=0; i
<n
; ++i
)
28 for (int j
=0; j
<=c
; ++j
)
31 priority_queue
<edge
> q
;
32 q
.push(edge(start
, 0, 0));
39 //printf("popped <%d, %d, %d>\n", u.i, u.g, u.w);
43 if (d
[u
.i
][u
.g
] < u
.w
) continue;
45 vector
<edge
> &v
= g
[u
.i
];
46 for (int j
=0; j
<v
.size(); ++j
){
47 int distance
= v
[j
].w
;
48 int neighbor
= v
[j
].i
;
49 for (int k
= distance
- u
.g
; k
<= c
+ distance
- u
.g
; ++k
){
50 int new_gas
= u
.g
- distance
+ k
;
51 if (k
>= 0 && 0 <= new_gas
&& u
.g
+ k
<= c
){
52 int w_extra
= k
*p
[u
.i
];
53 //assert(w_extra >= 0);
54 if (u
.w
+ w_extra
< d
[neighbor
][new_gas
]){
55 d
[neighbor
][new_gas
] = u
.w
+ w_extra
;
56 q
.push(edge(neighbor
, new_gas
, u
.w
+ w_extra
));
57 //printf(" pushed <%d, %d, %d>\n", neighbor, new_gas, u.w + w_extra);
69 scanf("%d %d", &n
, &m
);
70 for (int i
=0; i
<n
; ++i
){
76 scanf("%d %d %d", &u
, &v
, &d
);
77 g
[u
].push_back(edge(v
, 0, d
));
78 g
[v
].push_back(edge(u
, 0, d
));
85 scanf("%d %d %d", &c
, &s
, &e
);
86 int t
= dijkstra(s
, e
, c
);
90 printf("impossible\n");